class MedianFinder {
private:
    // 大根堆的数据 < 小根堆的数据
    priority_queue<int> left;   // 大根堆
    priority_queue<int, vector<int>, greater<int>> right;   // 小根堆

public:
    /** initialize your data structure here. */
    MedianFinder() {
        
    }
    
    void addNum(int num) {
        // 分类讨论
        if(left.size() == right.size()) // 左右两个堆的元素个数相同
        {
            if(left.empty() || num <= left.top())   // 放 left 里面
            {
                left.push(num);
            }
            else
            {
                right.push(num);
                left.push(right.top());
                right.pop();
            }
        }
        else
        {
            if(num <= left.top())
            {
                left.push(num);
                right.push(left.top());
                left.pop();
            }
            else
            {
                right.push(num);
            }
        }
    }
    
    double findMedian() {
        if(left.size() == right.size())
            return (left.top() + right.top()) / 2.0;
        else
            return left.top();
    }
};

/**
 * Your MedianFinder object will be instantiated and called as such:
 * MedianFinder* obj = new MedianFinder();
 * obj->addNum(num);
 * double param_2 = obj->findMedian();
 */